/*
 * Copyright 2008 Sebastian Köhler
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package calyriumdc.gui;

import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;

public class DownloadStatRenderer extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if ( isSelected ) {
            super.setForeground( table.getSelectionForeground() );
            super.setBackground( table.getSelectionBackground() );
        } else {
            super.setForeground( table.getForeground() );
            super.setBackground( table.getBackground() );
        }
        this.setFont( table.getFont() );
        if ( hasFocus ) {
            this.setBorder( UIManager.getBorder( "Table.focusCellHighlightBorder" ) );
            if ( table.isCellEditable( row, column ) ) {
                super.setForeground( UIManager.getColor( "Table.focusCellForeground" ) );
                super.setBackground( UIManager.getColor( "Table.focusCellBackground" ) );
            }
        } else {
            this.setBorder( null );
        }
        if(value instanceof JProgressBar) {
            return (JProgressBar)value;
        }
        if (value instanceof String && value.equals("download")) {
            setText(null);
            setIcon(new ImageIcon(this.getClass().getResource("resources/download16.png")));
        } else if(value instanceof String && value.equals("upload")) {
            setText(null);
            setIcon(new ImageIcon(this.getClass().getResource("resources/upload16.png")));
        } else {
            setIcon(null);
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        }
        
        return this;
    }
}
